package com.itianyu.blog.dao.beans;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.itianyu.blog.util.ProcessBBCode;

/**
 * 博文实体类
 * @author wumgji
 */
@Entity
@Table(name = "ENTRY")
public class Entry implements Serializable {

	// 各个字段的含义请查阅文档的数据库结构部分
	private static final long serialVersionUID = 1L;

	@Id
	@Column(name = "ENTRY_ID")
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private int entryId;

	@ManyToOne(targetEntity = com.itianyu.blog.dao.beans.User.class, optional = false)
	@JoinColumn(name = "USERNAME", referencedColumnName = "USERNAME")
	private User user;

	@Column(name = "TITLE")
	private String title;


	@Column(name = "USERNAME1")
	private String userName1;
	
	@Column(name = "DESCRIPTION")
	private String description;

	@Column(name = "COMMENT_TOTAL")
	private Integer commenttotal;
	
	@Lob
	@Column(name = "BODY")
	private String body;

	@Column(name = "CREATION_DATE")
	@Temporal(TemporalType.TIMESTAMP)
	private Date creationDate;

	@Column(name = "MODIFICATION_DATE")
	@Temporal(TemporalType.TIMESTAMP)
	private Date modificationDate;

	@ManyToMany(targetEntity = com.itianyu.blog.dao.beans.Tag.class)
	@JoinTable(joinColumns = @JoinColumn(name = "ENTRY_ID", referencedColumnName = "ENTRY_ID"), name = "REL_ENTRY_TAG", inverseJoinColumns = @JoinColumn(name = "TAG_ID", referencedColumnName = "TAG_ID"))
	private List<Tag> tags;

	@Column(name = "PUBLISHED")
	private boolean published;

	public Entry() {
		super();
	}

	public String getBodyProcessed() {
		ProcessBBCode bbCodeProcessor = new ProcessBBCode();
		bbCodeProcessor.setAcceptBBCode(true);
		bbCodeProcessor.setAcceptHTML(false);
		return bbCodeProcessor.prepareEntryText(body);
	}

	public int getEntryId() {
		return entryId;
	}

	public void setEntryId(int entryId) {
		this.entryId = entryId;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
    
	public String getUserName1() {
		return userName1;
	}

	public void setUserName1(String userName1) {
		this.userName1 = userName1;
	}
	
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getDescription() {
		return description;
	}

	public String getBody() {
		return body;
	}

	public void setBody(String body) {
		this.body = body;
	}

	public Date getCreationDate() {
		return creationDate;
	}

	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}

	public Date getModificationDate() {
		return modificationDate;
	}

	public void setModificationDate(Date modificationDate) {
		this.modificationDate = modificationDate;
	}

	public List<Tag> getTags() {
		return tags;
	}

	public void setTags(List<Tag> tags) {
		this.tags = tags;
	}

	public void setPublished(boolean published) {
		this.published = published;
	}

	public boolean isPublished() {
		return published;
	}
	public Integer getCommenttotal() {
		return commenttotal;
	}

	public void setCommenttotal(Integer commenttotal) {
		this.commenttotal = commenttotal;
	}

}
